﻿using System;
using System.Text.RegularExpressions;
using System.Windows.Data;
using System.Windows.Media;

namespace RaSuperGrid.SuperGrid.Converter
{
    class NameValueConverter : IValueConverter
    {
        private static readonly Regex _input
                                      = new Regex(@"[a-zA-Z]+",
                                                  RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string name = System.Convert.ToString(value);
            if (IsValidName(name))
            {
                return Brushes.Black as Brush;
            }
            else
            {
                return Brushes.Red as Brush;
            }
        }

        // One-way only.
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static bool IsValidName(string input)
        {
            return (_input.IsMatch(input));
        }
    }
}
